***********************************************************************************
** title: How to survey citizens’ compliance with COVID-19 public health measures**
** jounral: Journal of Experimental Political Science							 **
** authors:	Daoust et al. 													     **
** date:	June 2020															 **
** dataset: Léger																 **					
***********************************************************************************

*Study 3

*Load dataset
use "study3.dta", clear

*Note: to run the following, you need those two packages: cibar and grc1leg. Use the ssc install [cibar] [grc1leg] to use them.

**************************************************************
** 					Generate variables						**
**************************************************************

*Treatment v/s control group
gen face_saving=0
replace face_saving=1 if groupeQ61==2

*Compliance 
gen grocery=0 if Q61Ar1==2
replace grocery=0 if Q61Br1==2
replace grocery=1 if Q61Ar1==1
replace grocery=1 if Q61Br1==1
replace grocery=1 if Q61Br1==3 // Guilty-free choice
replace grocery=1 if Q61Ar1==9	
replace grocery=1 if Q61Br1==9

gen grocery_category=0 if Q61Ar1==2
replace grocery_category=0 if Q61Br1==2
replace grocery_category=1 if Q61Ar1==1
replace grocery_category=1 if Q61Br1==1
replace grocery_category=2 if Q61Br1==3 // Guilty-free choice
replace grocery_category=1 if Q61Ar1==9
replace grocery_category=1 if Q61Br1==9

gen see_someone=0 if Q61Ar2==2
replace see_someone=0 if Q61Br2==2
replace see_someone=1 if Q61Ar2==1
replace see_someone=1 if Q61Br2==1
replace see_someone=1 if Q61Br2==3 // Guilty-free choice
replace see_someone=1 if Q61Ar2==9
replace see_someone=1 if Q61Br2==9

gen see_someone_category=0 if Q61Ar2==2
replace see_someone_category=0 if Q61Br2==2
replace see_someone_category=1 if Q61Ar2==1
replace see_someone_category=1 if Q61Br2==1
replace see_someone_category=2 if Q61Br2==3 // Guilty-free choice
replace see_someone_category=1 if Q61Ar2==9
replace see_someone_category=1 if Q61Br2==9

gen receive_someone=0 if Q61Ar3==2
replace receive_someone=0 if Q61Br3==2
replace receive_someone=1 if Q61Ar3==1
replace receive_someone=1 if Q61Br3==1
replace receive_someone=1 if Q61Br3==3 // Guilty-free choice
replace receive_someone=1 if Q61Ar3==9
replace receive_someone=1 if Q61Br3==9

gen receive_someone_category=0 if Q61Ar3==2
replace receive_someone_category=0 if Q61Br3==2
replace receive_someone_category=1 if Q61Ar3==1
replace receive_someone_category=1 if Q61Br3==1
replace receive_someone_category=2 if Q61Br3==3 // Guilty-free choice
replace receive_someone_category=1 if Q61Ar3==9
replace receive_someone_category=1 if Q61Br3==9

gen hangout_other=0 if Q61Ar5==2
replace hangout_other=0 if Q61Br5==2
replace hangout_other=1 if Q61Ar5==1
replace hangout_other=1 if Q61Br5==1
replace hangout_other=1 if Q61Br5==3 // Guilty-free choice
replace hangout_other=1 if Q61Ar5==9
replace hangout_other=1 if Q61Br5==9

gen hangout_other_category=0 if Q61Ar5==2
replace hangout_other_category=0 if Q61Br5==2
replace hangout_other_category=1 if Q61Ar5==1
replace hangout_other_category=1 if Q61Br5==1
replace hangout_other_category=2 if Q61Br5==3 // Guilty-free choice
replace hangout_other_category=1 if Q61Ar5==9
replace hangout_other_category=1 if Q61Br5==9

gen work_outside=0 if Q61Ar4==2
replace work_outside=0 if Q61Br4==2
replace work_outside=1 if Q61Ar4==1
replace work_outside=1 if Q61Br4==1
replace work_outside=1 if Q61Br4==3 // Guilty-free choice
replace work_outside=1 if Q61Ar4==9
replace work_outside=1 if Q61Br4==9

gen public_transport=0 if Q61Ar6==2
replace public_transport=0 if Q61Br6==2
replace public_transport=1 if Q61Ar6==1
replace public_transport=1 if Q61Br6==1
replace public_transport=1 if Q61Br6==3 // Guilty-free choice
replace public_transport=1 if Q61Ar6==9
replace public_transport=1 if Q61Br6==9

*Sociodemographics 
gen female=0
replace female=1 if sexe==2

gen uni=0
replace uni=1 if SCOLA==4			
replace uni=. if SCOLA==9

tabulate PROV2, generate(region)
drop if region7==1				

gen quebec=0
replace quebec=1 if PROV2==5	

gen french=0
replace french=1 if LANGU==1	| LANGU==4	 | LANGU==7

gen english=0
replace english=1 if LANGU==2 | LANGU==5 

gen allo=0
replace allo=1 if LANGU==3 | LANGU==6

gen fr_en_allo=1 if french==1
replace  fr_en_allo=2 if english==1
replace  fr_en_allo=3 if allo==1

gen older=0
replace older=1 if age>3

*Other variables
gen ideology=Q40
replace ideology=. if ideology==99
replace ideology=ideology/10

gen language_used=0 if Q0==1
replace language_used=1 if Q0==2

**************************************************************
** 							Labels							**
**************************************************************
label variable female "Women"
label variable uni "University"
label variable region1 "British Columbia"
label variable region2 "Alberta"
label variable region3 "Prairies"
label variable region4 "Ontario"
label variable region5 "Quebec"
label variable region6 "Atlantic"

**************************************************************
** 				 			Figure 1						**
**************************************************************
*First, we generate the graph. Second, we save them individually. 
cibar see_someone [aweight=pond], over1(face_saving)  level(84) ///
		graphopts(ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("Mean of compliance")  title("Visit someone else's home", size(small)) ) 
graph save see_someone_study3.gph, replace

cibar receive_someone [aweight=pond], over1(face_saving)  level(84) ///
		graphopts( ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Have someone over" "who does not live with you", size(small)) ) 
graph save receive_someone_study3.gph, replace	
	
		
cibar hangout_other [aweight=pond], over1(face_saving)   level(84) ///
		graphopts( ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Get together outdoors" "with people who do not live with you", size(small)) ) 
graph save hangout_other_study3.gph, replace		
						
*Third, we merge them all three into one figure. Fourth, we save it. 
grc1leg  see_someone_study3.gph receive_someone_study3.gph hangout_other_study3.gph,  legendfrom(see_someone_study3.gph) ///
	row(1)  xsize(27) ysize(12) title("Study 3")
 graph save figure1_study3.gph, replace

**************************************************************
** 				 		Table SM1							**
**************************************************************

est clear 
eststo: quietly estpost sum older female uni english french allo region* [aweight=pond] 		
esttab  using "Descriptives.rtf", cells("min mean(fmt(3)) sd(fmt(3)) max count")  label   mlabels(,titles) replace
 
**************************************************************
** 				 		Table SM2							**
**************************************************************
ttest older , by(face_saving) 
ttest female, by(face_saving)
ttest uni, by(face_saving)
ttest french, by(face_saving)
ttest english, by(face_saving)
ttest allo, by(face_saving)
ttest region1, by(face_saving) // As can be seen from the "Label" subsection above (but note that they are different from Study 1 and 2), region1 is British Columbia
ttest region2, by(face_saving) // region2 is Alberta
ttest region3, by(face_saving) // region3 is Manitoba/Saskatchewan (Prairies)
ttest region4, by(face_saving) // region4 is Ontario
ttest region5, by(face_saving) // region5 is Québec
ttest region6, by(face_saving) // region6 is Atlantic
ttest ideology, by(face_saving)

**************************************************************
** 				 		Figure SM1							**
**************************************************************
*First, we generate the histograms. Second, we save them individually. 
hist see_someone_category,  title("Visit someone else's home") ///
			discrete ylabel(0(10)80) ytitle("Percent (%)") percent xtitle("") xlabel(-1 " " 0 "Yes" 1 "No" 2 `" "Only when necessary OR"  "occasionaly" "' 3 " ") 
graph save sm1_1.gph, replace
hist receive_someone_category, title("Have someone over" "who does not live with you") ///
			discrete ylabel(0(10)80) ytitle("Percent (%)") percent xtitle("") xlabel(-1 " " 0 "Yes" 1 "No" 2 `" "Only when necessary OR"  "occasionaly" "' 3 " ") 
graph save sm1_2.gph, replace
hist hangout_other_category, title("Get together outdoors" "with people who do not live with you") ///
		discrete ylabel(0(10)80) ytitle("Percent (%)") percent xtitle("") xlabel(-1 " " 0 "Yes" 1 "No" 2 `" "Only when necessary OR"  "occasionaly" "' 3 " ") 
graph save sm1_3.gph, replace

*Third, we merge them all three into one figure. 
graph combine sm1_1.gph sm1_2.gph sm1_3.gph, col(1) ysize(18) xsize(10)

**************************************************************
** 				 			Figure SM2						**
**************************************************************
*First, we run the logistic regressions. Second, we compute the marginal effect for "face_saving". 
*Third, we plot the effects. Fourth, we save each individual graph. 
eststo m1: logit see_someone face_saving ///
			older female uni english french allo region1 region2 region3 region4 region6  ideology
margins, at(face_saving=(0 1))
marginsplot, level(84) ytitle("Predicted probability") title("Visit someone else’s home")  ///
						plotopts(connect(none)) ylabel(0(.05).25) xtitle("") xlabel(-1 " " 2 " " 0 "Control" 1 `" "Face-saving"  "treatment" "', labsize(vsmall)) 
graph save  see_someone_sm2_study3.gph, replace

eststo m2:  logit receive_someone face_saving ///
			older female uni english french allo region1 region2 region3 region4 region6  ideology
margins, at(face_saving=(0 1))
marginsplot, level(84) ytitle("") title("Have someone over at your home" "who does not live with you")  ///
						plotopts(connect(none)) ylabel(0(.05).25) xtitle("") xlabel(-1 " " 2 " " 0 "Control" 1 `" "Face-saving"  "treatment" "', labsize(vsmall)) 
graph save  receive_someone_sm2_study3.gph, replace

eststo m3: logit hangout_other face_saving ///
			older female uni english french allo region1 region2 region3 region4 region6  ideology
margins, at(face_saving=(0 1)) 
marginsplot, level(84) ytitle("") title("Get together outdoors with people" "who do not live with you ")  ///
						plotopts(connect(none)) ylabel(0(.05).25) xtitle("") xlabel(-1 " " 2 " " 0 "Control" 1 `" "Face-saving"  "treatment" "', labsize(vsmall)) 
graph save  hangout_other_sm2_study3.gph, replace

*Fifth, we combine everything. Sixth, we save it. 
graph combine see_someone_sm2_study3.gph receive_someone_sm2_study3.gph hangout_other_sm2_study3.gph, row(1) xsize(9) title("Study 3")
graph save SM2_study3.gph, replace

**************************************************************
** 				 	Table SM3								**
**************************************************************
esttab m1 m2 m3 using "tableSM3.rtf", label mlabels(,titles) nogap nolines pr2  b(2) se(2)replace nostar

**************************************************************
** 				 	Figure SM3 & 4							**
**************************************************************

*See the .do for Study 1 and 2

**************************************************************
** 				 		Figure SM5							**
**************************************************************


*First, we run the logistic regressions. Second, we compute the marginal effect for "face_saving" using dydx across each group of interest (male/female; no university/university/; each 0-10 ideology scale value). 
*Third, we plot the effects. Fourth, we save each individual graph. 
*Fifth, we combine everything. Sixth, we save it. 
*We repeat this for all three variables (female, university, ideology)

*Female
logit see_someone i.face_saving##i.female
margins, dydx(face_saving) at(female=(0 1)) post
marginsplot, level(84) yline(0)  ylabel(-.1(.05).2) title("Visit someone else's home", size(small)) ///
				ytitle("Predicted probability") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 "Men" 1 "Women", labsize(vsmall)) xtitle("Sex")
graph save female1_study3.gph, replace

logit receive_someone i.face_saving##i.female
margins, dydx(face_saving) at(female=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Have someone over" "who does not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 "Men" 1 "Women", labsize(vsmall)) xtitle("Sex")
graph save female2_study3.gph, replace

logit hangout_other  i.face_saving##i.female
margins, dydx(face_saving) at(female=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Get together outdoors" "with people who do not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 "Men" 1 "Women", labsize(vsmall)) xtitle("Sex")
graph save female3_study3.gph, replace

graph combine female1_study3.gph female2_study3.gph female3_study3.gph, row(1) xsize(9)
graph save female_sm3_study3.gph, replace

*University
logit see_someone  i.face_saving##i.uni
margins, dydx(face_saving) at(uni=(0 1)) post
marginsplot, level(84) yline(0) ylabel(-.1(.05).2) title("Visit someone else's home", size(small)) ///
				ytitle("Predicted probability") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 `" "No uni"  "degree" "' 1 "Uni degree", labsize(vsmall)) xtitle("Education")
graph save uni1_study3.gph, replace

logit receive_someone i.face_saving##i.uni
margins, dydx(face_saving) at(uni=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Have someone over" "who does not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 `" "No uni"  "degree" "' 1 "Uni degree", labsize(vsmall)) xtitle("Education")
graph save uni2_study3.gph, replace

logit hangout_other  i.face_saving##i.uni
margins, dydx(face_saving) at(uni=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Get together outdoors" "with people who do not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 " " 2 " " 0 `" "No uni"  "degree" "' 1 "Uni degree", labsize(vsmall)) xtitle("Education")
graph save uni3_study3.gph, replace

graph combine uni1_study3.gph uni2_study3.gph uni3_study3.gph, row(1) xsize(9)
graph save uni_sm3_study3.gph, replace

*Ideology
logit see_someone i.face_saving##c.ideology
margins, dydx(face_saving) at(ideology=(0(.1)1)) post
marginsplot, level(84) yline(0) ylabel(-.1(.05).2) title("Visit someone else's home", size(small)) ///
				ytitle("Predicted probability")   xtitle("Left-right ideology")
graph save ideology1_study3.gph, replace

logit receive_someone i.face_saving##c.ideology
margins, dydx(face_saving) at(ideology=(0(.1)1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Have someone over" "who does not live with you", size(small)) ///
					ytitle("")   xtitle("Left-right ideology")
graph save ideology2_study3.gph, replace

logit hangout_other i.face_saving##c.ideology
margins, dydx(face_saving) at(ideology=(0(.1)1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Get together outdoors" "with people who do not live with you", size(small)) ///
				ytitle("")   xtitle("Left-right ideology")
graph save ideology3_study3.gph, replace

graph combine ideology1_study3.gph ideology2_study3.gph ideology3_study3.gph, row(1) xsize(9) 
graph save ideology_sm3_study3.gph, replace

*Seventh, we merge the three figures that combined three figures each.
graph combine  female_sm3_study3.gph uni_sm3_study3.gph ideology_sm3_study3.gph, col(1) ysize(9)

**************************************************************
** 			Figure SM6 - Replication without weight			**
**************************************************************
*First, we generate the graph. Second, we save them individually. 
cibar see_someone , over1(face_saving)  level(84) ///
		graphopts( ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("Mean of compliance")  title("Visit someone else's home", size(small)) ) 
graph save see_someone.gph, replace

cibar receive_someone , over1(face_saving)  ///
		graphopts( ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Have someone over" "who does not live with you", size(small)) ) 
graph save receive_someone.gph, replace	
		
cibar hangout_other , over1(face_saving)  ///
		graphopts( ylabel(0(.05).3) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Get together outdoors" "with people who do not live with you", size(small)) ) 
graph save hangout_other.gph, replace		
		
*Third, we merge them all three into one figure. Fourth, we save it. 
grc1leg  see_someone.gph receive_someone.gph hangout_other.gph,  legendfrom(see_someone.gph) ///
	row(1)  xsize(27) ysize(12) title("Study 3") 
graph save noweight_study3.gph, replace

**************************************************************
** 				 	Figure SM7 - other items				**
**************************************************************
*First, we generate the graph. Second, we save them individually. 
cibar grocery [aweight=pond], over1(face_saving)  ///
		graphopts( ylabel(0(.1)1) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Go to the grocery store", size(small)) ) 
graph save grocery.gph, replace	


cibar work_outside [aweight=pond], over1(face_saving)  ///
		graphopts( ylabel(0(.1)1) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Go to work outside your home", size(small)) ) 
graph save work_outside.gph, replace	

cibar public_transport [aweight=pond], over1(face_saving)  ///
		graphopts( ylabel(0(.1)1) legend(pos(6) row(1) order(1 "Control group" 2 "Face-saving treatment"))  ///
		ytitle("") title("Use public transportation", size(small)) ) 
graph save public_transport.gph, replace	

*Third, we merge them all three into one figure. Fourth, we save it. 
grc1leg   grocery.gph work_outside.gph public_transport.gph, legendfrom(grocery.gph)  row(1) xsize(9) title("Study 3")
graph save non_dangerous_items_study3.gph, replace 

**************************************************************
** 			Figure SM8 - language of the questionnaire		**
**************************************************************
logit see_someone  i.face_saving##i.language_used
margins, dydx(face_saving) at(language_used=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Visit someone else's home", size(small)) ///
				ytitle("AME of face-saving treatment") plotopts(connect(none)) xlabel(-1 " "  0  "English"  1 "French" 2 " ", labsize(vsmall)) xtitle("")
graph save languageused1_study3.gph, replace

logit receive_someone i.face_saving##i.language_used
margins, dydx(face_saving) at(language_used=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Have someone over" "who does not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 " "  0  "English"  1 "French" 2 " ", labsize(vsmall)) xtitle("")
graph save languageused2_study3.gph, replace

logit hangout_other  i.face_saving##i.language_used
margins, dydx(face_saving) at(language_used=(0 1)) post
marginsplot,  level(84) yline(0) ylabel(-.1(.05).2) title("Get together outdoors" "with people who do not live with you", size(small)) ///
				ytitle("") plotopts(connect(none)) xlabel(-1 " "  0  "English"  1 "French" 2 " ", labsize(vsmall)) xtitle("")
graph save languageused3_study3.gph, replace

graph combine languageused1_study3.gph languageused2_study3.gph languageused3_study3.gph, row(1) xsize(9) title("Study 3")
graph save languageused_study3.gph, replace

*******************************************************************************
**Merge figures from Study 1, 2, 3 to generated pooled Figures 1, SM2, SM6-8***
*******************************************************************************
*Figure 1:
graph combine figure1_study1.gph figure1_study2.gph figure1_study3.gph, col(1) xsize(8) ysize(12)

*Figure SM2:
graph combine SM2_study1.gph SM2_study2.gph SM2_study3.gph, col(1) xsize(8) ysize(12)

*Figure SM6:
graph combine noweight_study1.gph noweight_study2.gph noweight_study3.gph, col(1) xsize(8) ysize(12)

*Figure SM7:
graph combine non_dangerous_items_study1.gph non_dangerous_items_study2.gph non_dangerous_items_study3.gph, col(1) xsize(8) ysize(12)

*Figure SM8:
graph combine languageused_study1.gph languageused_study2.gph languageused_study3.gph, col(1) xsize(8) ysize(12)




